package com.sofwin;

import lombok.Data;

/**
 * @packageName: com.sofwin
 * @user: andyliu
 * @date: 2021/7/14 15:01
 * @email 115176513@qq.com
 * @description: 异步请求的返回结果
 */
@Data
public class AjaxResult {
    // 响应状态 200 400 404 500
    private Integer code;
    private String msg;
    private Object data;

    /**
     * 异步请求不需要返回数据
     * @return
     */
    public static AjaxResult success(){
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMsg("操作成功");
        return result;
    }

    /**
     * 操作成功并返回数据
     * @param data
     * @return
     */
    public static AjaxResult success(Object data){
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setData(data);
        return result;
    }
    public static AjaxResult success(String msg,Object data){
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static AjaxResult success(String msg){
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }
    public static AjaxResult error(){
        AjaxResult result = new AjaxResult();
        result.setCode(500);
        result.setMsg("操作失败");
        return result;
    }
    public static AjaxResult error(String msg){
        AjaxResult result = new AjaxResult();
        result.setCode(500);
        result.setMsg(msg);
        return result;
    }
    public static AjaxResult error(Integer code,String msg){
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
